package com.example.gulimallproduct.controller;

import java.util.Arrays;
import java.util.Map;
import java.util.Objects;

import com.example.gulimallproduct.request.SelectSpuOrSkuInfoPageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.example.gulimallproduct.entity.SkuInfoEntity;
import com.example.gulimallproduct.service.SkuInfoService;
import com.example.common.utils.PageUtils;
import com.example.common.utils.R;



/**
 * sku信息
 *
 * @author zzl
 * @email zzl@gmail.com
 * @date 2025-10-24 15:22:38
 */
@RestController
@RequestMapping("/skuinfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;
    /**
     * 获取sku名称
     */
    @GetMapping("/getSkuName")
    public String getSkuName(@RequestParam("skuId") Long skuId){
        SkuInfoEntity skuInfoEntity = skuInfoService.lambdaQuery().eq(SkuInfoEntity::getSkuId, skuId).select(SkuInfoEntity::getSkuName).one();
        if(Objects.isNull(skuInfoEntity)){
            return  null;
        }
        return skuInfoEntity.getSkuName();
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@Validated SelectSpuOrSkuInfoPageRequest selectSpuOrSkuInfoPageRequest){
        return skuInfoService.selectSkuInfo(selectSpuOrSkuInfoPageRequest);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{skuId}")
    public R info(@PathVariable("skuId") Long skuId){
		SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        return R.ok().put("skuInfo", skuInfo);
    }


    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.save(skuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] skuIds){
		skuInfoService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

}
